<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">ID</label>
        <el-input v-model="query.id" clearable placeholder="ID" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">姓名</label>
        <el-input v-model="query.patientName" clearable placeholder="姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">性别</label>
        <el-input v-model="query.gender" clearable placeholder="性别" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">家长姓名</label>
        <el-input v-model="query.parent" clearable placeholder="家长姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">家长联系方式</label>
        <el-input v-model="query.parentMobile" clearable placeholder="家长联系方式" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">主管医生ID，参考 t_doctor</label>
        <el-input v-model="query.doctorId" clearable placeholder="主管医生ID，参考 t_doctor" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">诊所ID</label>
        <el-input v-model="query.clinicId" clearable placeholder="诊所ID" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">所属部门</label>
        <el-input v-model="query.deptId" clearable placeholder="所属部门" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <date-range-picker
          v-model="query.birthDay"
          start-placeholder="birthDayStart"
          end-placeholder="birthDayStart"
          class="date-item"
        ></date-range-picker>
        <date-range-picker
          v-model="query.createDate"
          start-placeholder="createDateStart"
          end-placeholder="createDateStart"
          class="date-item"
        ></date-range-picker>
        <rrOperation :crud="crud"></rrOperation>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission"></crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="ID">
            <el-input v-model="form.id" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="form.patientName" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-radio v-for="item in dict.gender" :key="item.id" v-model="form.gender" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="出生日期">
            <el-date-picker v-model="form.birthDay" type="datetime" style="width: 370px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="家长姓名">
            <el-input v-model="form.parent" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="家长联系方式">
            <el-input v-model="form.parentMobile" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createDate" type="datetime" style="width: 370px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="主管医生ID，参考 t_doctor">
            <el-input v-model="form.doctorId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="诊所ID">
            <el-input v-model="form.clinicId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="所属部门">
            <el-input v-model="form.deptId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="是否标星收藏，0未收藏，1已收藏">
            <el-input v-model="form.star" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="患者头像URL">
            <el-input v-model="form.photoUrl" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="产品规则">
            <el-input v-model="form.productRuleId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="套餐规则">
            <el-input v-model="form.packageRuleId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="是否已归档 0 未归档 1 已归档 已归档普通查询不可见">
            <el-input v-model="form.archived" style="width: 370px;"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" stripe :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" sortable label="ID"></el-table-column>
        <el-table-column prop="patientName" sortable label="姓名"></el-table-column>
        <el-table-column prop="gender" sortable label="性别">
          <template slot-scope="scope">
            {{ dict.label.gender[scope.row.gender] }}
          </template>
        </el-table-column>
        <el-table-column prop="birthDay" width="150" sortable label="出生日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.birthDay) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="compliance" sortable label="患者依从性预测">
          <template slot-scope="scope">
            {{ dict.label.patient_compliance[scope.row.compliance] }}
          </template>
        </el-table-column>
        <el-table-column prop="parent" sortable label="家长姓名"></el-table-column>
        <el-table-column prop="relationship" sortable label="家长关系">
          <template slot-scope="scope">
            {{ dict.label.patient_parent_rel[scope.row.relationship] }}
          </template>
        </el-table-column>
        <el-table-column prop="parentProfession" sortable label="家长职业"></el-table-column>
        <el-table-column prop="parentMobile" sortable label="家长联系方式"></el-table-column>
        <el-table-column prop="orthodonticHis" sortable label="家长正畸史"></el-table-column>
        <el-table-column prop="createDate" sortable label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="doctorId" sortable label="主管医生ID"></el-table-column>
        <el-table-column prop="clinicId" sortable label="诊所ID"></el-table-column>
        <el-table-column prop="deptId" sortable label="所属部门"></el-table-column>
        <el-table-column prop="tags" sortable label="标签"></el-table-column>
        <el-table-column prop="star" sortable label="收藏"></el-table-column>
        <el-table-column prop="photoUrl" sortable label="患者头像URL"></el-table-column>
        <el-table-column prop="productRuleId" sortable label="产品规则"></el-table-column>
        <el-table-column prop="packageRuleId" sortable label="套餐规则"></el-table-column>
        <el-table-column prop="archived" sortable label="是否已归档">
          <template slot-scope="scope">
            {{ dict.label.patient_archive[scope.row.archived] }}
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','patient:edit','patient:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            ></udOperation>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination></pagination>
    </div>
  </div>
</template>

<script>
import crudPatient from '@/api/patient';
import CRUD, { presenter, header, form, crud } from '@crud/crud';
import rrOperation from '@crud/RR.operation';
import crudOperation from '@crud/CRUD.operation';
import udOperation from '@crud/UD.operation';
import pagination from '@crud/Pagination';
import DateRangePicker from '@/components/DateRangePicker';

const defaultForm = { id: null, patientName: null, gender: null, birthDay: null, compliance: null, parent: null, relationship: null, parentProfession: null, parentMobile: null, orthodonticHis: null, createDate: null, doctorId: null, clinicId: null, deptId: null, tags: null, star: null, photoUrl: null, productRuleId: null, packageRuleId: null, archived: null };
export default {
  name: 'Patient',
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['gender', 'patient_compliance', 'patient_parent_rel', 'patient_archive'],
  cruds() {
    return CRUD({ title: 'PatientService', url: '/patient/queryPage', sort: 'id,desc', crudMethod: { ...crudPatient } });
  },
  data() {
    return {
      permission: {
        add: ['admin', 'patient:add'],
        edit: ['admin', 'patient:edit'],
        del: ['admin', 'patient:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'ID' },
        { key: 'patientName', display_name: '姓名' },
        { key: 'gender', display_name: '性别' },
        { key: 'parent', display_name: '家长姓名' },
        { key: 'parentMobile', display_name: '家长联系方式' },
        { key: 'doctorId', display_name: '主管医生ID，参考 t_doctor' },
        { key: 'clinicId', display_name: '诊所ID' },
        { key: 'deptId', display_name: '所属部门' }
      ]
    };
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    }
  }
};
</script>

<style scoped>

</style>
